<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page contentType="text/html; UTF-8" pageEncoding="UTF-8" isELIgnored="false" %><!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>学生管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/back/statics/css/bootstrap3.min.css">
    <script src="${pageContext.request.contextPath}/back/statics/js/jquery-1.8.3.min.js"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4">
            <h1 class="text-center">学生管理</h1>
        </div>
    </div>
    <div class="row" style="margin-top: 10px;margin-bottom: 10px;">


        <div class="col-sm-10 ">
            <c:if test="${sessionScope.user.role=='admin'}">
                <div class="row col-sm-offset-0" style="float: left">
                    <div class="col-sm-12">
                        <a href="${pageContext.request.contextPath}/back/student/add.jsp" class="btn btn-success" >添加学生信息</a>
                    </div>
                </div>
            </c:if>

            <form class="form-inline col-sm-offset-1 text-center" action="${pageContext.request.contextPath}/student/findAll" method="post">

                <div class="form-group " >

                    <select class="form-control" name="searchCol" id="searchCol">
                        <option value="ts.name"
                                <c:if test="${requestScope.searchCol=='ts.name'}">
                                    selected
                                </c:if>
                        >姓名</option>
                        <option value="ts.s_number"
                                <c:if test="${requestScope.searchCol=='ts.s_number'}">
                                    selected
                                </c:if>

                        >学号</option>
                        <option value="ts.classid"
                                <c:if test="${requestScope.searchCol=='ts.classid'}">
                                    selected
                                </c:if>
                        >班级</option>
                        <option value="ts.phone"
                                <c:if test="${requestScope.searchCol=='ts.phone'}">
                                    selected
                                </c:if>
                        >电话</option>
                    </select>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="searchValue" value="${requestScope.searchValue}" id="searchValue" placeholder="请输入搜索关键词">
                </div>
                <button type="submit" class="btn btn-primary">查询</button>
            </form>
        </div>
    </div>
    <div class="row" style="height: 350px;">
        <div class="col-sm-12">
            <c:if test="${requestScope.students.size()==0}">
                <h1 class="text-center">
                    查询无结果！
                </h1>
            </c:if>

            <c:if test="${requestScope.students.size()!=0}">
                <table class="table table-striped table-bordered table-hover">
                    <tr>
                        <th>编号</th>
                        <th>姓名</th>
                        <th>学号</th>
                        <th>班级</th>
                        <th>年龄</th>
                        <th>生日</th>
                        <th>电话</th>
                        <th>QQ</th>
                        <th>城市</th>
                        <th>标签</th>
                        <th>备注</th>
                        <th>操作</th>
                    </tr>
                    <c:forEach items="${requestScope.students}" var="student">
                            <td id="id">
                                    ${student.id}
                            </td>
                            <td>${student.name}</td>
                            <td>${student.s_number}</td>
                            <td>${student.classid}</td>
                            <td>${student.age}</td>
                            <td><fmt:formatDate value="${student.bir}"></fmt:formatDate></td>
                            <td>${student.phone}</td>
                            <td>${student.qq}</td>
                            <td>
                                    ${student.cityid}
                                <c:if test="${student.cityid==NULL}">
                                    ${student.address.city_name}
                                </c:if>
                            </td>
                            <td>
                                 <c:if test="${student.tagid==''}">
                                     <c:if test="${student.tag.tag_name!=NULL}">
                                         ${student.tagid}
                                         ${student.tag.tag_name}
                                     </c:if>
                                 </c:if>
                                <c:if test="${student.tagid!=''}">
                                    <c:if test="${student.tag.tag_name!=NULL}">
                                        ${student.tagid}、
                                        ${student.tag.tag_name}
                                    </c:if>
                                </c:if>
                            </td>
                            <td>${student.mark}</td>
                            <td>
                                <c:if test="${sessionScope.user.role=='admin'}">
                                    <a href="${pageContext.request.contextPath}/student/delete/${student.id}" class="btn btn-danger btn-sm">删除</a>
                                    <a href="${pageContext.request.contextPath}/student/change/${student.id}" class="btn btn-primary btn-sm" id="change" >修改</a>
                                </c:if>
                                <c:if test="${sessionScope.user.role!='admin'}">
                                    暂无权限！
                                </c:if>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </c:if>

        </div>
    </div>

    <div class="row">
        <div class="col-sm-12 text-center">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <c:if test="${requestScope.pageNow>1}">
                        <li>
                            <a href="${pageContext.request.contextPath}/student/findAll?pageNow=${requestScope.pageNow-1}&searchCol=${requestScope.searchCol}&searchValue=${requestScope.searchValue}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                    </c:if>
                    <c:forEach begin="1" step="1" end="${requestScope.totalpage}" varStatus="state">
                        <c:if test="${requestScope.pageNow==state.count}">
                            <li class="active"><a href="javascript:;">${state.count}</a></li>
                        </c:if>
                        <c:if test="${requestScope.pageNow!=state.count}">
                            <li ><a href="${pageContext.request.contextPath}/student/findAll?pageNow=${state.count}&searchCol=${requestScope.searchCol}&searchValue=${requestScope.searchValue}">${state.count}</a></li>
                        </c:if>
                    </c:forEach>
                    <c:if test="${requestScope.pageNow<totalpage}">
                        <li>
                            <a href="${pageContext.request.contextPath}/student/findAll?pageNow=${requestScope.pageNow+1}&searchCol=${requestScope.searchCol}&searchValue=${requestScope.searchValue}" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </c:if>
                </ul>
            </nav>

        </div>
    </div>
</div>
</body>
</html>
<script>
    <%--$(function (){--%>
    <%--    $("#change").click(function(){--%>
    <%--        let a = $("#id").text();--%>
    <%--        alert(a);--%>
    <%--        $.post("${pageContext.request.contentType}/student/change",--%>
    <%--            {--%>
    <%--                id:$("#id").text()--%>
    <%--            },--%>
    <%--            function(data,status){--%>
    <%--            });--%>
    <%--    });--%>

    <%--})--%>
</script>
